import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  //主页
  {
    path: '/',
    name: 'index',
    component: () => import("../views/Index.vue"),
    children: [
      {
        path: '',
        redirect: '/home'
      },
      {
        path: "/home",
        name: "home",
        component: () => import("../views/home")
      },
      {
        path: "/commodity",
        name: "commodity",
        component: () => import("../views/commodity")
      },

      {
        path: "/order",
        name: "order",
        component: () => import("../views/order")
      },
      {
        path: "/me",
        name: "me",
        component: () => import("../views/me")
      }
    ]
  },
  //登录注册
  {
    path: "/login",
    name: "login",
    component: () => import('@/views/login/Login')
  },
  {
    path: "/verifyCode",
    name: "verifyCode",
    component: () => import('@/views/login/VerifyCode')
  },
  //订单结算
  {
    path: "/payment",
    name: "payment",
    component: () => import('@/views/commodity/payment')
  },//订单结算/添加备注
  {
    path: "/remark",
    name: "remark",
    component: () => import('@/views/commodity/remark')
  },
  //订单详情
  {
    path: "/orderDetail",
    name: "orderDetail",
    component: () => import('@/views/order/orderDetail')
  },
  //地址管理
  {
    path: "/addressList",
    name: "addressList",
    component: () => import('@/views/me/addressList')
  },
  {
    path: "/addressEdit",
    name: "addressEdit",
    component: () => import('@/views/me/addressEdit')
  },
  //门店选择
  {
    path: "/store",
    name: "store",
    component: () => import("../views/store")
  },
  //客服
  {
    path: "/service",
    name: "service",
    component: () => import("../views/me/service")
  },
  //关于我们
  {
    path: "/about",
    name: "about",
    component: () => import("../views/me/about")
  },
  //意见反馈
  {
    path: "/question",
    name: "question",
    component: () => import("../views/me/question")
  },
  {
    path: "/feedback",
    name: "feedback",
    component: () => import("../views/me/feedback")
  },
  //我的设置
  {
    path: "/setting",
    name: "setting",
    component: () => import("../views/me/setting")
  },
  //个人资料
  {
    path: "/person",
    name: "person",
    component: () => import("../views/me/person")
  },
  //红包卡券
  {
    path: "/coupon",
    name: "coupon",
    component: () => import("../views/me/coupon")
  },
];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes
});

//路由守卫
// router.beforeEach((to, from, next) => {
//   const isLogin = localStorage.app_login ? true : false;
//   if (to.path == "/login" || to.path == "/verifyCode") {
//     next();
//   } else {
//     //是否在登录状态下
//     isLogin ? next() : next("/login")
//   }
// })

export default router;
